home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls074c.sunsparc.Z / tls074c.sunsparc / lib / vtcl / examples / scale.tcl < prev    next >
Encoding:
Text File  |  1995-07-20  |  4.9 KB  |  200 lines

  1. #!/bin/vtcl
  2. # ---------------------------------------------------------------------
  3. # Copyright 1994 by SCO, Inc.
  4. # Permission to use, copy, modify, distribute, and sell this software
  5. # and its documentation for any purpose is hereby granted without fee,
  6. # provided that the above copyright notice appear in all copies and that
  7. # both that copyright  notice  and  this  permission  notice  appear  in
  8. # supporting documentation, and that the name  of  SCO  not  be used  in
  9. # advertising or publicity pertaining  to distribution of  the  software
  10. # without   specific,   written  prior   permission.    SCO   makes   no
  11. # representations  about  the  suitability  of  this  software  for  any
  12. # purpose.  It is provided "as is" without express or implied warranty.
  13. # ---------------------------------------------------------------------
  14.  
  15. # Demo        : scale.tcl
  16. # Description    : Manipulate the scale widget's resources via text widgets
  17. #          and togglebutton. Employs Tcl "switch" command.
  18. #          VtSetValues, VtGetValues          
  19. # Notes:    : 
  20. #  
  21.  
  22. proc QuitCB {cbs} {
  23.     VtClose; exit 0
  24. }
  25.  
  26. # Grab values from the scale and update the text widgets.
  27. #
  28. proc UpdateTextValues {form} {
  29.     global horizontalScaleW verticalScaleW 
  30.  
  31.     set value [VtGetValues $horizontalScaleW -value]
  32.     set min   [VtGetValues $horizontalScaleW -min]
  33.     set max   [VtGetValues $horizontalScaleW -max]
  34.  
  35.     VtSetValues $form.minTextW -value $min
  36.     VtSetValues $form.maxTextW -value $max
  37.     VtSetValues $form.valueTextW -value $value
  38. }
  39.  
  40.  
  41. # Depending on the option passed, update the specified scale 
  42. # widget resource (title, mininum value, maximum value, etc...)
  43. #
  44. proc SetSelectedScaleResourceCB {option cbs} {
  45.     global horizontalScaleW verticalScaleW
  46.  
  47.     switch $option {
  48.         "value" {
  49.             set widgetValue [keylget cbs value]
  50.             VtSetValues $horizontalScaleW -value $widgetValue
  51.             VtSetValues $verticalScaleW -value $widgetValue
  52.         }
  53.         "min" {
  54.             set widgetValue [keylget cbs value]
  55.             VtSetValues $horizontalScaleW -min $widgetValue
  56.             VtSetValues $verticalScaleW -min $widgetValue
  57.         }
  58.         "max" {
  59.             set widgetValue [keylget cbs value]
  60.             VtSetValues $horizontalScaleW -max $widgetValue
  61.             VtSetValues $verticalScaleW -max $widgetValue
  62.         }
  63.         "title" {
  64.             set widgetValue [keylget cbs value]
  65.             VtSetValues $horizontalScaleW -title $widgetValue
  66.             VtSetValues $verticalScaleW -title $widgetValue
  67.         }
  68.         "showValue" {
  69.             #
  70.                 #toggle button uses "set" not "value"
  71.             #
  72.             set widgetValue [keylget cbs set]
  73.             VtSetValues $horizontalScaleW -showValue $widgetValue
  74.             VtSetValues $verticalScaleW -showValue $widgetValue
  75.         }
  76.     }
  77. }
  78.  
  79. proc UpdateScaleValueCB {cbs} {
  80.     # call this function to make sure the other scale
  81.     # is reflecting the same value.
  82.     SetSelectedScaleResourceCB "value" $cbs
  83.     set form [keylget cbs dialog]
  84.     UpdateTextValues $form
  85. }
  86.  
  87. #
  88. # Start Program
  89. #
  90. set app [VtOpen scales]
  91.  
  92. set mainForm [VtFormDialog $app.form \
  93.     -title "Scales" \
  94.     -okCallback QuitCB \
  95.     ]
  96.  
  97. set scaleFrame [VtFrame $mainForm.scaleFrame \
  98.     -title "Scales" \
  99.     -shadowType ETCHED_OUT \
  100.     ]
  101. set smallForm [VtForm $scaleFrame.smallForm \
  102.     ]
  103.  
  104. set horizontalScaleW [VtScale $smallForm.scale_horz \
  105.     -callback UpdateScaleValueCB \
  106.     -horizontal \
  107.     -min 10 \
  108.     -max 100 \
  109.     -value 50 \
  110.     -topSide FORM \
  111.     -leftSide FORM \
  112.     ]
  113.  
  114. set verticalScaleW [VtScale $smallForm.scale_vert \
  115.     -callback UpdateScaleValueCB \
  116.     -vertical \
  117.     -min 10 \
  118.     -max 100 \
  119.     -value 50 \
  120.     -leftSide FORM \
  121.     -topOffset 20 \
  122.     -topSide $horizontalScaleW \
  123.     ]
  124.  
  125. set titleLabelW [VtLabel $mainForm.titleLabelW \
  126.     -label "Enter Title:" \
  127.     -topSide FORM \
  128.     -leftSide $scaleFrame \
  129.     -leftOffset 10  \
  130.     -topOffset  10  \
  131.     ]
  132.  
  133. set titleTextW [VtText $mainForm.titleTextW \
  134.     -callback "SetSelectedScaleResourceCB title" \
  135.     -columns 15 \
  136.     -topSide FORM  \
  137.     -leftSide $titleLabelW \
  138.     -rightSide FORM \
  139.     -topOffset  10  \
  140.     ]
  141.  
  142. set valueLabelW [VtLabel $mainForm.valueLabelW \
  143.     -label "Value:" \
  144.     -rightSide $titleTextW\
  145.     -leftSide $scaleFrame \
  146.     -topSide $mainForm.titleTextW  \
  147.     -labelRight \
  148.     ]
  149.  
  150. set valueTextW [VtText $mainForm.valueTextW \
  151.     -callback "SetSelectedScaleResourceCB value" \
  152.     -columns 3 \
  153.     -leftSide $valueLabelW \
  154.     -topSide $titleTextW]
  155.  
  156. set minLabelW [VtLabel $mainForm.minLabelW \
  157.     -label "Min:" \
  158.     -leftSide $scaleFrame \
  159.     -rightSide $valueTextW \
  160.     -topSide $valueTextW \
  161.     -labelRight \
  162.     ]
  163.  
  164. set minTextW [VtText $mainForm.minTextW \
  165.     -callback "SetSelectedScaleResourceCB min" \
  166.     -columns 3 \
  167.     -leftSide $minLabelW \
  168.     -topSide $valueTextW \
  169.     ]
  170.  
  171. set maxLabelW [VtLabel $mainForm.maxLabelW \
  172.     -label "Max:" \
  173.     -leftSide $scaleFrame \
  174.     -rightSide $minTextW \
  175.     -topSide $minTextW \
  176.     -labelRight \
  177.     ]
  178.  
  179. set maxTextW [VtText $mainForm.maxTextW \
  180.     -callback "SetSelectedScaleResourceCB max" \
  181.     -columns 3 \
  182.         -leftSide $maxLabelW \
  183.     -topSide $minTextW \
  184.     ]
  185.  
  186.  
  187. set showValue [VtToggleButton $mainForm.showValue \
  188.     -label "Show Scale Value" \
  189.     -value 1 \
  190.     -callback "SetSelectedScaleResourceCB showValue" \
  191.     -topSide $maxTextW \
  192.     -leftSide $maxLabelW \
  193.     ]
  194.  
  195. UpdateTextValues $mainForm
  196.  
  197. VtShow $mainForm
  198. VtMainLoop
  199.  
  200.